package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-10 23:04
 **/
public class JianZhiOffer56I {

    public int[] singleNumbers(int[] nums) {
        int a = 0;
        for (int num : nums) {
            a ^= num;
        }
        int m = 1;
        while ((a & m) == 0) {
            m <<= 1;
        }

        int x = 0;
        int y = 0;
        for (int num : nums) {
            if ((m & num) == 0) {
                x ^= num;
            } else {
                y ^= num;
            }
        }
        return new int[]{x, y};
    }

}
